// Tradex.Connectivity.Rithmic.h

#pragma once

#include "vcclr.h"

#include "RApi.h"
#include "NativeConnector.h"

using namespace System;
using namespace System::Collections::Generic;
using namespace System::Data::Common;
using namespace System::IO;
using namespace System::Reflection;
using namespace RApi;

using namespace Tradex;
using namespace Tradex::Market;
using namespace Tradex::Trading;
using namespace Tradex::Connectivity::ConnectorModel;

namespace Tradex {
	namespace Connectivity {
		namespace Rithmic {

			class NativeConnector;

			public ref class RithmicConnector :
				IConnector,
				IMarketConnector,
				ITradingConnector
			{

				public:

				[System::Security::SecurityCritical()]
				RithmicConnector ();

				[System::Security::SecurityCritical()]
				~RithmicConnector ();
			
				// IConnector - start

				virtual void SetCallback(IConnectorCallback^ callback);

				[System::Security::SecurityCritical()]
				virtual void Connect (String^ connectionString);
				
				[System::Security::SecurityCritical()]
				virtual void Disconnect ();
				
				virtual property bool IsConnected { bool get(); }

				void OnLogEntry (
					System::Diagnostics::TraceLevel traceLevel,
					String^ subject,
					String^ message,
					String^ origin,
					String^ reference
				);

				void OnStatusUpdate (
					ConnectionStatusCode code,
					String^ message
				);

				// IConnector - end

				// IMarketConnector - start

				virtual void SetCallback(IMarketConnectorCallback^ callback);

				[System::Security::SecurityCritical()]
				virtual void Subscribe (InstrumentKey^ instrument, ActivityFilters filter);

				[System::Security::SecurityCritical()]
				virtual void Subscribe (MarketKey^ market, ActivityFilters filter);

				[System::Security::SecurityCritical()]
				virtual void GetReferenceData (InstrumentKey^ instrument);

				void OnActivity (InstrumentKey^ instrument, Activity^ Activity);

				void OnReferenceUpdate (InstrumentKey^ instrument, InstrumentInfo^ instrumentInfo, InstrumentPricing^ instrumentPricing);

				// IMarketConnector - end

				// ITradingConnectorCallback - start

				virtual void SetCallback (ITradingConnectorCallback^ callback);

				[System::Security::SecurityCritical()]
				virtual void GetAccounts ();

				[System::Security::SecurityCritical()]
				virtual void GetAccountOrders (AccountKey^ account);

				[System::Security::SecurityCritical()]
        		virtual void ReplayExecutions(AccountKey^ account, DateTime startMoment, DateTime endMoment);

				[System::Security::SecurityCritical()]
        		virtual void ReplayOrders(AccountKey^ account, DateTime startMoment, DateTime endMoment);

				[System::Security::SecurityCritical()]
				virtual void CreateOrder (
					AccountKey^ accountKey,
					OrderKey^ orderKey,
					OrderInfo^ orderInfo
				);

				[System::Security::SecurityCritical()]
				virtual void ModifyOrder (
					AccountKey^ accountKey,
					OrderKey^ orderKey, OrderId^ orderConnectionKey,
					OrderInfo^ orderInfo,
					OrderModification^ orderModification
				);

				[System::Security::SecurityCritical()]
				virtual void CancelOrder (
					AccountKey^ accountKey,
					OrderKey^ orderKey,
					OrderId ^orderConnectionKey
				);

				[System::Security::SecurityCritical()]
				virtual void CancelOrders ( 
					AccountKey^ accountKey
				);

				void OnAccountUpdate (AccountKey^ account, AccountUpdate^ accountUpdate, PositionUpdate^ position);

				void OnOrderUpdate (AccountKey^account, OrderKey^ orderKey, OrderId^ connectionKey, OrderUpdate^ orderProgress, OrderExecution^ execution);

				void OnOrdersUpdate(AccountKey^ account, array<OrderUpdate^>^ orders);

				// ITradingConnectorCallback - end

			    virtual property String^ ConfigFolder {
			        String^ get();
					void set(String^ folder);
			    }

				virtual property String^ LogFile {
			        String^ get();
					void set(String^ folder);
			    }

				internal:
				Dictionary<String^, int>^ pOrderCodeMap;

				private:
				NativeConnector* pNative;
				String^ pRithmicDirectory;
				String^ pRithmicLogFile;

				IConnectorCallback^ pConnectorCallback;

				IMarketConnectorCallback^ pMarketConnectorCallback;
				Dictionary<MarketKey^, ActivityFilters>^ _MarketSubscriptions;
				Dictionary<InstrumentKey^, ActivityFilters>^ _InstrumentSubscriptions;

				ITradingConnectorCallback^ pTradingConnectorCallback;

			};

		}
	}
}
